<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controller library
jimport('joomla.application.component.controller');
 
/**
 * Retail Shop Component Controller
 */
class RetailShopControllerHome extends JController
{
    function display()
	{			
		parent::display();
	}
	
	function findthelocalfreashop()
	{		
		$mainframe = JFactory::getApplication();
		$model = $this->getModel('RetailShop');
        
		$country = $model->getArrCountry();		
		$catagory = $model->getCategory();		
		$view = $this->getView('Home','html');
        $eventsAll = $model->getArrAllEvent();
        
		$view->assign('catagorys',$catagory);		
		$view->assign('countrys',$country);		
		 $catagorys_Menu = $model->getCategory();
        $view->assign('catagorys_Menu',$catagorys_Menu);
		$country_id=getRequest( 'country_id');     		
        $view->assign('eventsAll',$eventsAll);
		$view->setLayout('findthelocalfreashop');
		$view->findthelocalfreashop();
	}
	
	function checkmaillink(){
		$mainframe = JFactory::getApplication();
		$model = $this->getModel('RetailShop');
		$link = $_POST['shop_link'];
		$mail = $_POST['shop_email'];
		$return = $model->checkmaillink($link, $mail);
		
		echo $return;
		$mainframe->close();
	}
	
	function listcity()
  {
    $mainframe = JFactory::getApplication();
	$model = $this->getModel('RetailShop');
	$country_id = getRequest('country_id');
	$select_id = getRequest('select_id');
	//var_dump($select_id);  exit();
	$return = '<option value="-1"> --- Select State --- </option>';
	$citys = $model->getArrCity($country_id);
	foreach($citys as $city){
		if($select_id == $city->id){
			$return .="<option value='".$city->id."'  selected='selected' >".JText::_($city->name)."</option>";
		}
		$return .="<option value='".$city->id."'>".JText::_($city->name)."</option>";
	}
	echo $return; 
    $mainframe->close();
 
  }
  
	function startretailshop(){		
		if($_SESSION['__default']['user']->id != 0){
						
			$view = $this->getView('Home','html');
			$view->setLayout('startretailshop');
			$model = $this->getModel('RetailShop');		
			$catagorys_Menu = $model->getCategory();
			$myshop = $model->checkusershop($_SESSION['__default']['user']->id);
			if($myshop != 0){				
				$eventsAll = $model->getArrAllEvent();
				$catagorys = $model->getCategory();
				$countrys = $model->getArrCountry();				
				$view->assign('eventsAll',$eventsAll);				
				$view->assign('catagorys',$catagorys);
				$view->assign('countrys',$countrys);
				$view->assign('myshop',$myshop);
				
				$view->assign('exists',true);
				
				
			}else{
				$country = $model->getArrCountry();
				$catagory = $model->getCategory();
				
				$view->assign('country',$country);
				$view->assign('catagory',$catagory);
				
				
			}
			
			$view->assign('catagorys_Menu',$catagorys_Menu);
			$view->startretailshop();	
		}else{
			header('Location: index.php?option=com_users&view=login');
		}
		
	}
	function retailshop(){
		$view = $this->getView('Home','html');
		$model = $this->getModel('RetailShop');
		$shops = $model->getallshop();
		$view->setLayout('retailshop');
		$view->assign('shops',$shops);
		$view->retailshop();
	}
	
	function defaultcity(){	   
		$view = $this->getView('Home','html');
		$model = $this->getModel('RetailShop');		
		
		$shops = $model->getShopDefaultCity();		
		$view->setLayout('defaultcity');
		
        $eventsAll = $model->getArrAllEvent();
		$catagorys = $model->getCategory();
		$countrys = $model->getArrCountry();
         $catagorys_Menu = $model->getCategory();
        $view->assign('catagorys_Menu',$catagorys_Menu);
        $view->assign('eventsAll',$eventsAll);
		$view->assign('shops',$shops);
		$view->assign('catagorys',$catagorys);
		$view->assign('countrys',$countrys);
		$view->defaultcity();
	}
	
	function listalldeal(){		
		$mainframe = JFactory::getApplication();		
		$model = $this->getModel('RetailShop');
		$listdeals = $model->listdeals();		
		$countrys = $model->getArrCountry();		
		$catagorys = $model->getCategory();
        
		$view = $this->getView('Home','html');
		$view->setLayout('listalldeal');
        $eventsAll = $model->getArrAllEvent();
        $view->assign('eventsAll',$eventsAll);
		$view->assign('listdeals',$listdeals);
        $catagorys_Menu = $model->getCategory();
        $view->assign('catagorys_Menu',$catagorys_Menu);
		$view->assign('catagorys',$catagorys);		
		$view->assign('countrys',$countrys);
		$view->listalldeal();
	}
	
	function events(){
		$mainframe = JFactory::getApplication();
		$model = $this->getModel('RetailShop');		

		$countrys = $model->getArrCountry();		
		$catagorys = $model->getCategory();	
        $events = $model->getArrAllEvent('20');	
        
		$view = $this->getView('Home','html');
        $eventsAll = $model->getArrAllEvent();
        $view->assign('eventsAll',$eventsAll);
		$view->assign('catagorys',$catagorys);
        $catagorys_Menu = $model->getCategory();
        $view->assign('catagorys_Menu',$catagorys_Menu);		
		$view->assign('countrys',$countrys);
        $view->assign('events',$events);				
		$view->setLayout('events');
		$view->events();
	}	
    
	function search(){
		$mainframe = JFactory::getApplication();		
		$model = $this->getModel('RetailShop');					
		$tagfix = $model->search();
		echo $tagfix;
		$mainframe->close();
	}
	
	function addnewshop(){
		$mainframe = JFactory::getApplication();		
		$model = $this->getModel('RetailShop');
		
		$mainframe->close();
	}	
	function detailscatelog(){			
		$view = $this->getView('Home','html');
		$model = $this->getModel('RetailShop');			
		$id = $_GET['id'];
		$shops = $model->getShopByCatelogy($id);
		$catagorys = $model->getCategory();
		$countrys = $model->getArrCountry();
		$view->setLayout('detailscatelog');
        $eventsAll = $model->getArrAllEvent();
        $catagorys_Menu = $model->getCategory();
        $view->assign('catagorys_Menu',$catagorys_Menu);
        $view->assign('eventsAll',$eventsAll);
		$view->assign('shops',$shops);
		$view->assign('catagorys',$catagorys);
		$view->assign('countrys',$countrys);
		$view->detailscatelog();
	}	
	function saveshop(){
		$model = $this->getModel('RetailShop');		
		$model->saveShop();
		header('Location: index.php?option=com_retailshop&view=myshop');
	}
	
	function changeprofile(){	
		$shop_id = $_GET['myshop'];
		
		if($_SESSION['__default']['user']->id != 0){		
			$view = $this->getView('Home','html');
			$view->setLayout('startretailshop');
			$model = $this->getModel('RetailShop');		
			
			$myshop = $model->checkusershop($_SESSION['__default']['user']->id);			
			if($myshop != 0){												
				$countrys = $model->getArrCountry();								
				$view->assign('countrys',$countrys);
				$view->assign('myshop',$myshop);
				
				$shopinfo = $model->getShop($myshop);
				$country = $model->getArrCountry();
				$catagory = $model->getCategory();
				$addressAllShop = $model->addressAllShop($myshop);
				
				$view->assign('country',$country);
				$view->assign('catagory',$catagory);
				$view->assign('shopinfo',$shopinfo);
				$view->assign('addressAllShop',$addressAllShop);
				
			}else{
				header('Location: index.php?view=home&task=startretailshop');
			}			
			
			$view->startretailshop();	
		}else{
			header('Location: index.php?option=com_users&view=login');
		}
		
	}
}	